Skip to content

Conversation

ahtesham-quraish
Copy link
Contributor

@ahtesham-quraish ahtesham-quraish commented Jul 28, 2025

Description

Replace connect with useSelector() and useDispatch() 2/5 #2314

Supporting information

Link to other information about the change, such as GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.

Testing instructions

Please provide detailed step-by-step instructions for manually testing this change.

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.

Best Practices Checklist

We're trying to move away from some deprecated patterns in this codebase. Please
check if your PR meets these recommendations before asking for a review:

  • Any new files are using TypeScript (.ts, .tsx).
  • Deprecated propTypes, defaultProps, and injectIntl patterns are not used in any new or modified code.
  • Tests should use the helpers in src/testUtils.tsx (specifically initializeMocks)
  • Do not add new fields to the Redux state/store. Use React Context to share state among multiple components.
  • Use React Query to load data from REST APIs. See any apiHooks.ts in this repo for examples.
  • All new i18n messages in messages.ts files have a description for translators to use.
  • Imports avoid using ../. To import from parent folders, use @src, e.g. import { initializeMocks } from '@src/testUtils'; instead of from '../../../../testUtils'

Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.45%. Comparing base (0e1550a) to head (eb476c8).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2333   +/-   ##
=======================================
  Coverage   94.44%   94.45%           
=======================================
  Files        1169     1169           
  Lines       25102    25130   +28     
  Branches     5473     5490   +17     
=======================================
+ Hits        23708    23736   +28     
+ Misses       1328     1322    -6     
- Partials       66       72    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines 70 to 74
// const showAdvancedSettingsCardsBaseProps = {
// isAdvancedCardsVisible: false,
// showAdvancedCards: jest.fn(),
// setResetTrue: jest.fn(),
// };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this or any unnecessary comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@ahtesham-quraish ahtesham-quraish force-pushed the ahtesham/#2314 branch 2 times, most recently from 4a5c655 to 0cfc7f8 Compare July 30, 2025 09:47
Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It's a nice refactor and I'm excited to have this in place. However, could you please make sure to review #2343 and rebase this on top of it, before proceeding?

beforeEach(() => {
initializeMocks();
initializeMocks({
initialState,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing initialState twice (to initializeMocks and editorRender) is redundant - please see the fixes in #2343

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the initialState from initializeMocks

@@ -17,6 +17,49 @@ jest.mock('./settingsComponents/SwitchEditorCard', () => 'SwitchEditorCard');
jest.mock('./settingsComponents/TimerCard', () => 'TimerCard');
jest.mock('./settingsComponents/TypeCard', () => 'TypeCard');

jest.mock('../../../../../data/redux', () => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please declare this using the EditorState type (or PartialEditorState from #2343) so we know that the types are valid. I suspect there are some issues here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the PartialEditorState from #2343 you can check that

@ahtesham-quraish ahtesham-quraish force-pushed the ahtesham/#2314 branch 5 times, most recently from a9ab34f to a414746 Compare August 4, 2025 11:05
@ahtesham-quraish
Copy link
Contributor Author

ahtesham-quraish commented Aug 4, 2025

@bradenmacdonald thank you for highlighting the typed issues I have tried to fix them in my current PR and will fix the remaining ones in follow-up PRs. I have gone through the #2343 and approved it, after its merge I will rebase my branch

@bradenmacdonald
Copy link
Contributor

Thanks @ahtesham-quraish. I've merged it now so you can rebase this branch.

@ahtesham-quraish
Copy link
Contributor Author

@bradenmacdonald I have rebased my branch with #2343 please re-review my PR

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks @ahtesham-quraish. I have one question about preloadedState being {} vs undefined which I'd like to know before merging. The rest is minor/optional.

},
}));
import { screen, initializeMocks } from '@src/testUtils';
import { editorRender } from '../../../../../editorTestRender';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { editorRender } from '../../../../../editorTestRender';
import { editorRender, type PartialEditorState } from '@src/editors/editorTestRender';

@@ -36,19 +16,24 @@ jest.mock('../../../../../sharedComponents/TinyMceWidget', () => ({
default: () => <div>TinyMceWidget</div>,
}));

describe('SolutionWidget', () => {
const props = {
const initialState = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const initialState = {
const initialState: PartialEditorState = {

settings: { solutionExplanation: 'This is my solution' },
},
app: {
learningContextId: 'course+org+run',
images: {},
isLibrary: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isLibrary: false,

I know you didn't add this line, but once we put the types in you can see it needs to be removed.

},
}));
import { screen, initializeMocks } from '@src/testUtils';
import { editorRender } from '../../../../../editorTestRender';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { editorRender } from '../../../../../editorTestRender';
import { editorRender, type PartialEditorState } from '@src/editors/editorTestRender';

@@ -39,23 +13,25 @@ jest.mock('@src/editors/sharedComponents/TinyMceWidget/hooks', () => ({

jest.mock('@src/editors/sharedComponents/TinyMceWidget', () => ('TinyMceWidget'));

describe('QuestionWidget', () => {
const props = {
const initialState = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const initialState = {
const initialState: PartialEditorState = {

@@ -131,36 +154,36 @@ const SettingsWidget = ({
{!isLibrary && (
<div className="my-3">
<ResetCard
showResetButton={settings.showResetButton}
showResetButton={settings.showResetButton!}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
showResetButton={settings.showResetButton!}
showResetButton={settings.showResetButton || false}

Nit: this would be nicer than using ! I think.

@@ -194,7 +194,7 @@ export interface EditorState {

export { actions, selectors };

export function initializeStore(preloadedState = undefined) {
export function initializeStore(preloadedState = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is {} a better default than undefined ? I thought if we left this undefined it would use the "normal" initial state, whereas if we set it, it will use an empty initial state with no keys or values. But I could be wrong.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 15, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @ahtesham-quraish!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Submit a signed contributor agreement (CLA)

⚠️ We ask all contributors to the Open edX project to submit a signed contributor agreement or indicate their institutional affiliation.
Please see the CONTRIBUTING file for more information.

If you've signed an agreement in the past, you may need to re-sign.
See The New Home of the Open edX Codebase for details.

Once you've signed the CLA, please allow 1 business day for it to be processed.
After this time, you can re-run the CLA check by adding a comment below that you have signed it.
If the CLA check continues to fail, you can tag the @openedx/cla-problems team in a comment for further assistance.

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Aug 15, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Needs Tests Run or CLA Signed in Contributions Aug 21, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Tests Run or CLA Signed to In Eng Review in Contributions Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

4 participants